package com.chen.recruit.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import com.chen.recruit.domain.Role;
import com.chen.recruit.service.MenuService;
import com.chen.recruit.service.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 自定义权限验证接口扩展
 *
 * @author cgy
 * @date 2022/8/23
 */
@Component
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private final RoleService roleService;
    private final MenuService menuService;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return menuService.getMenuPermissionsByUserId(loginId);
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return roleService.getRolesByUserId(loginId).stream().map(Role::getCode).collect(Collectors.toList());
    }

}
